package com.wq.recruit.controller;

import com.wq.common.entity.PageResult;
import com.wq.common.entity.Result;
import com.wq.common.entity.StatusCode;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wq.recruit.entity.Enterprise;
import com.wq.recruit.service.EnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("enterprise")
@CrossOrigin
public class EnterpriseController {
    @Autowired
    private EnterpriseService enterpriseService;

    @GetMapping("hotlist")
    public Result hotList(@RequestParam(value = "ishot", defaultValue = "1") String ishot) {
        List<Enterprise> enterprises = enterpriseService.hotList(ishot);
        return new Result(true, StatusCode.OK, "热门企业查询成功", enterprises);
    }

    @GetMapping("search/{page}/{size}")
    public Result search(@RequestBody Map map, @PathVariable int page, @PathVariable int size) {
        Page<Enterprise> enterprisePage = enterpriseService.search(map, page, size);
        return new Result(true, StatusCode.OK, "热门企业查询成功", new PageResult<Enterprise>(enterprisePage.getTotal(), enterprisePage.getRecords()));
    }
}